﻿using Project.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;


namespace Project.DAL
{
    public class DbContextFactory
    {
        /// <summary>
        /// 获取数据上下文（单例）
        /// </summary>
        /// <returns></returns>
        public static DbContext Create() {
            var dbcontext = CallContext.GetData("DbContext") as Entity;
            if (dbcontext==null)
            {
                dbcontext = new Entity();
                //禁止使用导航属性
                //dbContext.Configuration.ProxyCreationEnabled = false;
                CallContext.SetData("DbContext", dbcontext);
            }
            return dbcontext;
        }
    }
}
